{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os, sys\n",
    "sys.path.append(\"/home/zhubenjin/codebase/det3d.pytorch\")\n",
    "\n",
    "import torch "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# %matplotlib inline \n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from lib.visualization.show import visualize_feature_maps "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import cv2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "task_pred = np.fromfile(\"/home/zhubenjin/codebase/det3d.pytorch/task_pred.bin\", dtype=np.float32).reshape(-1, 40, 2)\n",
    "visualize_feature_maps(task_pred[:, :, 0:1]) \n",
    "visualize_feature_maps(task_pred[:, :, 1:2]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "task_pred_epoch_1 = np.fromfile(\"/home/zhubenjin/codebase/det3d.pytorch/test.bin\", dtype=np.float32).reshape(-1, 40, 2)\n",
    "visualize_feature_maps(task_pred_epoch_1[:, :, 0:1]) \n",
    "visualize_feature_maps(task_pred_epoch_1[:, :, 1:2]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# box = np.fromfile(\"/home/zhubenjin/codebase/det3d.pytorch/bev.bin\", dtype=np.uint8).reshape(600, 640, 3)\n",
    "box_canonical = np.fromfile(\"/home/zhubenjin/codebase/det3d.pytorch/bev_canonical_sidev.bin\", dtype=np.uint8).reshape(600, 640, 3)\n",
    "# visualize_feature_maps(box[:, :, 1:2]) \n",
    "visualize_feature_maps(box_canonical[:, :, 1:2]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "task_pred_epoch_1 = np.fromfile(\"/home/zhubenjin/codebase/det3d.pytorch/task_pred_epoch_1_no_backward.bin\", dtype=np.float32).reshape(-1, 40, 2)\n",
    "visualize_feature_maps(task_pred_epoch_1[:, :, 0:1]) \n",
    "visualize_feature_maps(task_pred_epoch_1[:, :, 1:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "labels = np.fromfile(\"/home/zhubenjin/repos/det3d.velocity.pytorch/labels.bin\", dtype=np.int32).reshape(500, 500, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "bev = np.fromfile(\"/home/zhubenjin/repos/det3d.velocity.pytorch/bev.bin\", dtype=np.float32).reshape(1000, 1000, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gt_boxes = np.fromfile(\"/home/zhubenjin/repos/det3d.velocity.pytorch/gt_boxes.bin\", dtype='float64').reshape(-1, 9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "labels_anchor0 = cv2.resize(labels[:, :, 0:1], (1000, 1000), interpolation=cv2.INTER_NEAREST)\n",
    "labels_anchor1 = cv2.resize(labels[:, :, 1:2], (1000, 1000), interpolation=cv2.INTER_NEAREST)\n",
    "if labels.shape[2] == 4:\n",
    "    labels_anchor2 = cv2.resize(labels[:, :, 2:3], (1000, 1000), interpolation=cv2.INTER_NEAREST)\n",
    "    labels_anchor3 = cv2.resize(labels[:, :, 3:4], (1000, 1000), interpolation=cv2.INTER_NEAREST)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gt_boxes.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from lib.core import box_np_ops"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# gt_boxes[:,6] = -1 * gt_boxes[:,6] - 0.5 * np.pi\n",
    "gts = box_np_ops.rbbox3d_to_corners(gt_boxes[:, [0,1,2,3,4,5,8]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gts = (gts//0.1 + bev.shape[0] * 0.5).astype(np.int32).transpose(0,2,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "gts.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "visualize_feature_maps(bev, anno=gts, axes=[0,1]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "visualize_feature_maps(labels_anchor0[:, :, np.newaxis]+bev, anno=gts, axes=[0,1]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "visualize_feature_maps(labels_anchor1[:, :, np.newaxis]+bev, anno=gts, axes=[0,1]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "visualize_feature_maps(labels_anchor2[:, :, np.newaxis]+bev, anno=gts, axes=[0,1]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "visualize_feature_maps(labels_anchor3[:, :, np.newaxis]+bev, anno=gts, axes=[0,1]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
